package com.zwd.deep.controller;


import cn.hutool.core.bean.BeanUtil;
import com.zwd.deep.common.RequestResult;
import com.zwd.deep.entity.dto.DiagnosisDto;
import com.zwd.deep.entity.po.Diagnoses;
import com.zwd.deep.entity.vo.DiagnosesVo;
import com.zwd.deep.service.IDiagnosesService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 诊断记录表
 *
 * @author zwd
 * @since 2025-02-12
 */
@RestController
@RequestMapping("/diagnoses")
@AllArgsConstructor
@Slf4j
@Validated
public class DiagnosesController {

    private final IDiagnosesService diagnosisService;

    /**
     * 获取患者诊断记录
     * @param userId 用户ID
     * @return 诊断记录列表
     */
    @GetMapping("/user/{userId}")
    public RequestResult<List<DiagnosesVo>> getDiagnosisRecords(@PathVariable Integer userId) {
        log.info("getDiagnosisRecords userId: {}", userId);
        List<DiagnosesVo> diagnosisRecordDtos = diagnosisService.getDiagnosisRecords(userId);
        return RequestResult.success(diagnosisRecordDtos);
    }

    /**
     * 获取诊断记录详情
     * @param diagnosisId
     * @return
     */
    @GetMapping("/diagnosis")
    public RequestResult<DiagnosesVo> getDiagnosis(Integer diagnosisId) {
        log.info("getDiagnosis diagnosisId: {}", diagnosisId);
        Diagnoses diagnoses = diagnosisService.getById(diagnosisId);
        DiagnosesVo diagnosesVo = new DiagnosesVo();
        BeanUtil.copyProperties(diagnoses, diagnosesVo);
        return RequestResult.success(diagnosesVo);
    }

    /**
     * 新增诊断记录
     * @param diagnosisDto 诊断记录参数
     * @return 新增结果
     */
    @PostMapping("/diagnosis")
    public RequestResult<Integer> addDiagnosis(@Validated @RequestBody DiagnosisDto diagnosisDto) {
        log.info("addDiagnosis diagnosisDto: {}", diagnosisDto);
        Integer diagnosisId = diagnosisService.addDiagnosis(diagnosisDto);
        return RequestResult.success(diagnosisId);
    }

}
